package com.zh.spring.ai.controller;

import com.zh.spring.ai.constant.Constants;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/aiChat/")
public class AIChatController {
    //spring.ai.chat.client.enabled default is true.
    private final ChatClient chatClient;

    public AIChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    //user can input contents and AI model will response as a string.
    @GetMapping(Constants.apiVersion1 + "/test")
    public String generation(String userInput) {
        return this.chatClient.prompt().user(userInput).call().content();

    }
}
